package com.ruoyi.web.controller.task;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.task.domain.EquipmentConfig;
import com.ruoyi.task.domain.SubBankServerConfig;
import com.ruoyi.task.service.ISubBankServerConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/server/config")
public class ServerConfigController extends BaseController {

    @Autowired
    ISubBankServerConfigService iSubBankServerConfigService;

    @PreAuthorize("@ss.hasPermi('server:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubBankServerConfig config)
    {
        startPage();
        List<SubBankServerConfig> list = iSubBankServerConfigService.selectServerConfigList(config);
        return getDataTable(list);
    }

    /**
     * 新增参数配置
     */
    @PreAuthorize("@ss.hasPermi('server:config:add')")
    @Log(title = "服务器参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SubBankServerConfig config)
    {
        config.setCreateBy(getUsername());
        config.setUpdateBy(getUsername());
        return toAjax(iSubBankServerConfigService.insertConfig(config));
    }


    @PreAuthorize("@ss.hasPermi('server:config:remove')")
    @Log(title = "服务器参数管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configIds}")
    public AjaxResult remove(@PathVariable Long[] configIds)
    {
        iSubBankServerConfigService.deleteConfigByIds(configIds);
        return success();
    }

    /**
     * 获取网点摄像头配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:config:query')")
    @GetMapping(value = "/{serverId}")
    public AjaxResult getInfo(@PathVariable("serverId") Long serveId)
    {
        return success(iSubBankServerConfigService.selectServerConfigByServerId(serveId));
    }

    @PreAuthorize("@ss.hasPermi('equipment:config:edit')")
    @Log(title = "网点摄像头配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubBankServerConfig subBankServerConfig)
    {
        subBankServerConfig.setUpdateBy(getUsername());
        return toAjax(iSubBankServerConfigService.updateSubSeverConfig(subBankServerConfig));
    }
}
